package com.cai.jobs;

import com.cai.constant.RedisConstant;
import com.cai.utils.aliyunUtil;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        //计算差值
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if(sdiff!=null){
            for (String s : sdiff) {
                //删除服务器上的垃圾图片
                aliyunUtil.deleteFile(s);
                //删除redis集合中的垃圾图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,s);
                System.out.println(s);//测试打印垃圾图片的名字
            }
        }


    }
}
